module.exports = (function() {
    var express = require('express');
    var router = express.Router();
    var path = require('path');
    var uid = require('uid');
    var config = require('./../config.json');
    var request = require('request');
    router.get('/', function(req, res) {
        for (var c in req.cookies) {
            res.clearCookie(c);
        }
        res.sendFile(path.join(__dirname, './authenticateViews/register1.html'));
    });
    //是否被占用
    router.get('/usernameoccupied/:username', function(req, res, next) {
        var url = config.adminBaseUrl + "/usernameoccupied/" + req.params.username;
        request({
            url: url
        }, function(err, response, body) {
            if (!err && response.statusCode == 200) {
                res.send(body);
            } else {
                res.send(true);
            }
        });
    });
    var redis = require('redis');
    router.post('/', function(req, res) {
        var body = req.body;
        res.cookie('username', body.username, {
            expires: new Date(Date.now() + 3600 * 1000 * 24 * 10)
        });
        res.cookie('password', body.password);
        res.redirect('/register2');
        // res.sendFile(path.join(__dirname, './../views/register2.html'));
    });
    return router;
})();
